//
// Created by Semir on 2020/6/9.
//

#include <iostream>
#include <vector>

using namespace std;

int maxProfit(vector<int>& prices) {
    if (prices.size() < 2) {
        return 0;
    }
    int profit = 0;
    int min = prices[0];
    for (int i = 1; i < prices.size(); i++) {
        if (prices[i] <= min) {
            min = prices[i];
        } else {
            int tmp = prices[i] - min;
            if (tmp > profit) {
                profit = tmp;
            }
        }
    }
    return profit;
}

int main() {
    vector<int> prices = {7,6,4,3,1};
    int profit = maxProfit(prices);
    cout << profit << endl;
    return 0;
}